<template>

  <div class="contentCate">
    <el-row>
      <el-input v-model="searchParams.userId" placeholder="请输入赠送用户id" clearable style="width:200px"
        size="mini"></el-input>
      <el-input v-model="searchParams.giveId" placeholder="请输入受赠用户id" clearable style="width:200px"
        size="mini"></el-input>
      <el-select v-model="searchParams.status" placeholder="请选择状态" clearable :style="{ width: '150px' }" size="mini">
        <el-option v-for="item in statusData" :key="item.id" :label="item.name" :value="item.id"></el-option>
      </el-select>
      <el-button type="primary" icon="el-icon-search" size="mini" @click="getData"
        v-if="has('blindBoxGiveOrders/index')">搜索</el-button>
      <el-button type="info" icon="el-icon-refresh" size="mini" @click="reset"
        v-if="has('blindBoxGiveOrders/index')">重置</el-button>
    </el-row>
    <el-table :data="data.data" style="width: 100%;margin:10px auto" row-key="id" v-loading="table_loading"
      :row-class-name="tableRowClassName" :expand-row-keys="expands"
      :header-cell-style="{ background: '#f3f8fe', color: '#333' }" @expand-change="handleExpandChange">
      <el-table-column type="expand">
        <template slot-scope="scope">
          <div class="dange_con_box">
            <div class="zs_dange_box" v-for="(item, index) in scope.row.details" :key="index">
              <div class="image_box">
                <img :src="item.prize_image" alt="">
              </div>
              <div class="name_box">{{ item.prize_name }}</div>
              <div class="jiage_box">
                <div>￥：{{ item.prize_price }}</div>
                <div style="color: blueviolet">数量：x{{ item.prize_num }}</div>
              </div>
            </div>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="ID" prop="id">
      </el-table-column>
      <el-table-column label="赠送用户的Id" prop="user_id">
      </el-table-column>
      <el-table-column label="受赠用户的Id" prop="give_id">
      </el-table-column>
      <el-table-column label="总价值" prop="total_amount">
      </el-table-column>
      <el-table-column label="时间" prop="created_at">
      </el-table-column>
      <el-table-column label="备注" prop="remark">
      </el-table-column>
      <el-table-column label="状态" prop="status">
        <template slot-scope="scope">
          <span :style="{color:( scope.row.status==1?'':'red')}">{{ scope.row.status==1?'已通过':scope.row.status==2?'已驳回' :'待审核' }}</span>
          </template>
      </el-table-column>

      <el-table-column label="操作" fixed="right" width="300">
        <template slot-scope="scope">
          <el-button size="mini" :disabled="scope.row.status==0?false:true" slot="reference" type="success"
            @click="tgconfirm('1', scope.row)">{{ scope.row.status==1?'已审核':'审核' }}</el-button>
          <el-button size="mini" type="danger"  @click="tgconfirm('2', scope.row)"  :disabled="scope.row.status==0?false:true">{{ scope.row.status==2?'已驳回':'驳回' }}</el-button>

        </template>
      </el-table-column>
    </el-table>
    <el-pagination background style="text-align:center;margin:20px 0;" :current-page="searchParams.page"
        :page-sizes="pageSizes" layout="total,prev, pager, next,sizes" :total="data.total" @size-change="changeSize"
        @current-change="changePage"></el-pagination>
  </div>
</template>



<script>
import api from "../../api/api.js";
export default {
  data() {
    return {
      dialogVisible: false,
      data: [], // 表格诗句
      expands: [],
      table_loading: true, // 表格加载中
      loading: false, //全局加载中
      pageSizes: [10, 20, 50, 100, 200, 500, 800, 1000, 2000], // 每页条数默认10
      searchParams: {
        page: 1,
        limit: 10,
        giveId: "",
        status: "",
        userId: ""
      },
      
      statusData: [
        { id: 0, name: "未通过" },
        { id: 1, name: "已通过" },
      ],
    }
  },
  created() {
    this.getData()
  },
  methods: {
    // 加载中
    load() {
      this.loading = this.$loading({
        lock: true,
        text: "数据加载中",
        spinner: "el-icon-loading",
        background: "rgba(0, 0, 0, 0.7)"
      });
    },
    // 取消加载
    unload() {
      this.loading.close();
    },
    // 初始化
    init() {
      this.searchParams.page = 1;
      this.searchParams.giveId = "";
      this.searchParams.userId = "";
      this.searchParams.status = "";
      this.getData()
    },
    // 获取所有数据
    getData() {
      this.table_loading = true;
      api.blindBoxGiveOrders
        .index({ params: this.searchParams })
        .then(res => {
          if (res.data.code == 200) {
            this.table_loading = false;
            this.data = res.data.data;
          }
        })
        .catch(error => {
          console.log(error);
        });
    },
    tableRowClassName({ row, rowIndex }) {
      if (row.status == '0') {
        return 'warning-row';
      } else if (row.status == '1') {
        return 'success-row';
      }
      return '';
    },
    handleExpandChange(row, expandedRows) {
      if (expandedRows.length) {
        this.expands = [row.id];
      } else {
        this.expands = [];
      }
    },
    tgconfirm(status, e) {
      this.dialogVisible = true
      this.$confirm(`确认${status==1?'通过':'驳回'}？`)
        .then(_ => {
          this.load();
          api.blindBoxGiveOrders
            .status(e.id, { status })
            .then(res => {
              this.unload();
              if (res.data.code === 200) {
                this.$message.success("审核成功");
                this.init();
              }
            })
            .catch(error => {
              console.log(error);
            });
        })
        .catch(_ => { });

    },
    // 改变每页条数时
    changeSize(limit) {
      this.searchParams.limit = limit;
      this.getData();
    },
    // 改变当前页码时
    changePage(page) {
      this.searchParams.page = page;
      this.getData();
    },
  }
}
</script>

<style lang="less">
::-webkit-scrollbar {
  display: none;
}

.demo-table-expand {
  font-size: 0;
}

.demo-table-expand label {
  width: 90px;
  color: #99a9bf;
}

.demo-table-expand .el-form-item {
  margin-right: 0;
  margin-bottom: 0;
  width: 50%;
}

.contentCate {
  margin: 0 auto;

  .search {
    margin: 0 auto 10px auto;
  }
}


.dange_con_box {
  width: 100%;
  display: flex;
  justify-content: flex-start;
  flex-wrap: wrap;
  overflow-x: auto;

  .zs_dange_box {
    width: 120px;
    height: 180px;
    margin-right: 10px;
    margin-bottom: 10px;
    flex-shrink: 0;
    box-shadow: 5px 5px 10px 0 rgba(0, 0, 0, 0.5);

    .image_box {
      width: 100%;
      height: 120px;

      img {
        width: 100%;
        height: 100%;
      }
    }

    .jiage_box {
      width: 100%;
      height: 20px;
      color: red;
      display: flex;
      justify-content: space-between;
      align-items: center;

    }

    .name_box {
      width: 100%;
      height: 40rpx;
      display: -webkit-box;
      color: black;
      -webkit-line-clamp: 2;
      /* 限制为 3 行 */
      -webkit-box-orient: vertical;
      overflow: hidden;
    }
  }
}

.el-table .warning-row {
  background: oldlace;
}

.el-table .success-row {
  // background: #f0f9eb;
}
</style>